package day5;

import java.util.Scanner;


//连续最大和
public class oj2 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] array = new int[n];
        for(int i = 0; i < n; i++) {
            array[i] = scan.nextInt();

        }
        int sum = array[0];
        int max = array[0];
        for(int i = 1; i < n; i++) {
            sum = getMax(sum + array[i],array[i]);

            if(sum > max) {
                max = sum;
            }

        }
        System.out.println(max);
    }
    public static int getMax(int a, int b) {
        return a > b ? a : b;
    }
}
